/*
 * 编码格式转码
 */

//字符串转十六进制
export function stringToHex(str) {
    let val = '';
    for (let i = 0; i < str.length; i++) {
        if (val == '')
		    val = str.charCodeAt(i).toString(16);
	    else
		    val += '-' + str.charCodeAt(i).toString(16);
    }
    return val;
}

//十六进制转字符串
export function hexToString(str) {
    /* let trimedStr = str.trim();
    let rawStr =
        trimedStr.substr(0, 2).toLowerCase() === '0x' ? trimedStr.substr(2) : trimedStr;
    let len = rawStr.length;
    if (len % 2 !== 0) {
        return '';
    }
    let curCharCode;
    let resultStr = [];
    for (let i = 0; i < len; i = i + 2) {
        curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
        resultStr.push(String.fromCharCode(curCharCode));
    }
    return resultStr.join(''); */
    let val = '';
    let arr = str.split('-');
    for(var i = 0; i < arr.length; i++){
    　　val += String.fromCharCode(parseInt(arr[i],16));
    }
    return val;
}

// 字符串转base64 
export function stringToBase64(str) {
  return encodeURIComponent(Base64.encode(str));
}

// base64转字符串
export function base64ToString(str) {
  return Base64.decode(decodeURIComponent(str));
}